package com.quanquan.user.configBeans;

import utils.DateUtils;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 *
 * @ClassName: TimeTransformation
 * @Author: xiaoqianh丶
 * @Date: 2019-06-04 14:29
 * @Version: V1.0
 */
public class TimeTransformation {

    /**
     * 按日整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Long> formatDay(Map<String, Long> map) {
        Map<String, Long> newMap = new LinkedHashMap<>();
        List<String> weekDateList = DateUtils.dateList(7);
        System.out.println(weekDateList);
        for (String weekDate : weekDateList) {
            //如果传入的map中包含这个键，不动
            if (map.containsKey(weekDate.substring(0, 10))) {
                newMap.put(weekDate.substring(5, 10), map.get(weekDate.substring(0, 10)));
            } else {
                //如果不包含补0
                newMap.put(weekDate.substring(5, 10),0L);
            }
        }
        return newMap;
    }

    /**
     * 按周整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Long> formatWeek(Map<String, Long> map) {
        Map<String, Long> newMap = new LinkedHashMap<>();
        List<String> weekList = DateUtils.weekList(7);
        System.out.println(weekList);
        for (String week : weekList) {
            //如果传入的map中包含这个键，不动
            if (map.containsKey(week.substring(0, 7))) {
                newMap.put(week.substring(0, 7), map.get(week.substring(0, 7)));
            } else {
                //如果不包含补0
                newMap.put(week.substring(0, 7), 0L);
            }
        }
        return newMap;
    }

    /**
     * 按月整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Long> formatMonth(Map<String, Long> map) {
        Map<String, Long> newMap = new LinkedHashMap<>();
        List<String> monthList = DateUtils.monthList(7);
        System.out.println(monthList);
        for (String month : monthList) {
            //如果传入的map中包含这个键，不动
            if (map.containsKey(month.substring(0, 7))) {
                newMap.put(month.substring(0, 7), map.get(month.substring(0, 7)));
            } else {
                //如果不包含补0
                newMap.put(month.substring(0, 7), 0L);
            }
        }
        return newMap;
    }

    /**
     * 按年整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Long> formatYear(Map<String, Long> map) {
        Date date = new Date();
        String year = DateUtils.dateToString(date, DateUtils.DATE).substring(0, 4);
        Map<String, Long> newMap = new LinkedHashMap<>();
        //如果传入的map中包含这个键，不动
        if (map.containsKey(year.substring(0, 4))) {
            newMap.put(year.substring(0, 4), map.get(year.substring(0, 4)));
        } else {
            //如果不包含补0
            newMap.put(year.substring(0, 4), 0L);
        }
        return newMap;
    }



    /**
     * 按日整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Double> formatDay2(Map<String, Double> map) {
        Map<String, Double> newMap = new LinkedHashMap<>();
        List<String> weekDateList = DateUtils.dateList(7);
        System.out.println(weekDateList);
        for (String weekDate : weekDateList) {
            //如果传入的map中包含这个键，不动
            if (map.containsKey(weekDate.substring(0, 10))) {
                newMap.put(weekDate.substring(5, 10), map.get(weekDate.substring(0, 10)));
            } else {
                //如果不包含补0
                newMap.put(weekDate.substring(5, 10),0.0);
            }
        }
        return newMap;
    }

    /**
     * 按周整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Double> formatWeek2(Map<String, Double> map) {
        Map<String, Double> newMap = new LinkedHashMap<>();
        List<String> weekList = DateUtils.weekList(7);
        System.out.println(weekList);
        for (String week : weekList) {
            //如果传入的map中包含这个键，不动
            if (map.containsKey(week.substring(0, 7))) {
                newMap.put(week.substring(0, 7), map.get(week.substring(0, 7)));
            } else {
                //如果不包含补0
                newMap.put(week.substring(0, 7), 0.0);
            }
        }
        return newMap;
    }

    /**
     * 按月整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Double> formatMonth2(Map<String, Double> map) {
        Map<String, Double> newMap = new LinkedHashMap<>();
        List<String> monthList = DateUtils.monthList(7);
        System.out.println(monthList);
        for (String month : monthList) {
            //如果传入的map中包含这个键，不动
            if (map.containsKey(month.substring(0, 7))) {
                newMap.put(month.substring(0, 7), map.get(month.substring(0, 7)));
            } else {
                //如果不包含补0
                newMap.put(month.substring(0, 7), 0.0);
            }
        }
        return newMap;
    }

    /**
     * 按年整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Double> formatYear2(Map<String, Double> map) {
        Date date = new Date();
        String year = DateUtils.dateToString(date, DateUtils.DATE).substring(0, 4);
        Map<String, Double> newMap = new LinkedHashMap<>();
        //如果传入的map中包含这个键，不动
        if (map.containsKey(year.substring(0, 4))) {
            newMap.put(year.substring(0, 4), map.get(year.substring(0, 4)));
        } else {
            //如果不包含补0
            newMap.put(year.substring(0, 4), 0.0);
        }
        return newMap;
    }


    /**
     * 按日整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Integer> formatDay3(Map<String, Integer> map) {
        Map<String, Integer> newMap = new LinkedHashMap<>();
        List<String> weekDateList = DateUtils.dateList(7);
        System.out.println(weekDateList);
        for (String weekDate : weekDateList) {
            //如果传入的map中包含这个键，不动
            if (map.containsKey(weekDate.substring(0, 10))) {
                newMap.put(weekDate.substring(5, 10), map.get(weekDate.substring(0, 10)));
            } else {
                //如果不包含补0
                newMap.put(weekDate.substring(5, 10),0);
            }
        }
        return newMap;
    }

    /**
     * 按周整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Integer> formatWeek3(Map<String, Integer> map) {
        Map<String, Integer> newMap = new LinkedHashMap<>();
        List<String> weekList = DateUtils.weekList(7);
        System.out.println(weekList);
        for (String week : weekList) {
            //如果传入的map中包含这个键，不动
            if (map.containsKey(week.substring(0, 7))) {
                newMap.put(week.substring(0, 7), map.get(week.substring(0, 7)));
            } else {
                //如果不包含补0
                newMap.put(week.substring(0, 7), 0);
            }
        }
        return newMap;
    }

    /**
     * 按月整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Integer> formatMonth3(Map<String, Integer> map) {
        Map<String, Integer> newMap = new LinkedHashMap<>();
        List<String> monthList = DateUtils.monthList(7);
        System.out.println(monthList);
        for (String month : monthList) {
            //如果传入的map中包含这个键，不动
            if (map.containsKey(month.substring(0, 7))) {
                newMap.put(month.substring(0, 7), map.get(month.substring(0, 7)));
            } else {
                //如果不包含补0
                newMap.put(month.substring(0, 7), 0);
            }
        }
        return newMap;
    }

    /**
     * 按年整理数据
     *
     * @param map
     * @return
     */
    public static Map<String, Integer> formatYear3(Map<String, Integer> map) {
        Date date = new Date();
        String year = DateUtils.dateToString(date, DateUtils.DATE).substring(0, 4);
        Map<String, Integer> newMap = new LinkedHashMap<>();
        //如果传入的map中包含这个键，不动
        if (map.containsKey(year.substring(0, 4))) {
            newMap.put(year.substring(0, 4), map.get(year.substring(0, 4)));
        } else {
            //如果不包含补0
            newMap.put(year.substring(0, 4), 0);
        }
        return newMap;
    }

}
